package test.test_7_10;

import java.util.Arrays;
import java.util.Comparator;

/*
给定一个字符串数组
String[] strings = {"Java", "Python", "C", "Scala", "JavaScript"};
使用Lambda表达式和`Arrays.sort`方法根据字符串长度进行排序
 */
public class Demo01 {
    public static void main(String[] args) {
        String[] strings = {"Java", "Python", "C", "Scala", "JavaScript"};
//        Arrays.sort(strings, new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.length() - o2.length();
//            }
//        });

        //使用Lambda表达式
        Arrays.sort(strings,((o1, o2) -> o2.length() - o1.length()));
        for (String string : strings) {
            System.out.println(string);
        }

    }
}
